//
//  MJ_ScreenViewController.m
//  UEAssistant
//
//  Created by mac on 2018/1/10.
//  Copyright © 2018年 youyixinxi. All rights reserved.
//

#import "MJ_ScreenViewController.h"
#import "MJ_ScreeningButton.h"
#import "MJ_LanguageSelectController.h"
@interface MJ_ScreenViewController ()
@property (weak, nonatomic) IBOutlet MJ_ScreeningButton *startBtn;
@property (weak, nonatomic) IBOutlet MJ_ScreeningButton *endBtn;

@property (copy, nonatomic)NSString *sourceLanguageKey;
@property (copy, nonatomic)NSString *targetLanKey;
@end

@implementation MJ_ScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"筛选";
    _sourceLanguageKey = @"";
    _targetLanKey = @"";
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"重置" forState:UIControlStateNormal];
    [rightBtn setTitleColor:mainColor forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [rightBtn addTarget:self action:@selector(rightPressed:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}

- (void)rightPressed:(UIButton *)sender {
    _sourceLanguageKey = @"";
    _targetLanKey = @"";
    [_startBtn setTitle:@"源语言" forState:UIControlStateNormal];
    [_endBtn setTitle:@"目标语言" forState:UIControlStateNormal];
}

//源语言
- (IBAction)startBtnPressed:(MJ_ScreeningButton *)sender {
    __weak typeof(self) wSelf = self;
    MJ_LanguageSelectController *vc = [[MJ_LanguageSelectController alloc] init];
    vc.SelectLanguageBlock = ^(NSString *key, NSString *value) {
        __strong typeof(wSelf) sSelf = wSelf;
        sSelf.sourceLanguageKey = key;
        [sender setTitle:value forState:UIControlStateNormal];
    };
    [self presentViewController:vc animated:YES completion:nil];
    
}
//目标语言
- (IBAction)endBtnPressed:(MJ_ScreeningButton *)sender {
    __weak typeof(self) wSelf = self;

    MJ_LanguageSelectController *vc = [[MJ_LanguageSelectController alloc] init];
    vc.SelectLanguageBlock = ^(NSString *key, NSString *value) {
        __strong typeof(wSelf) sSelf = wSelf;
        sSelf.targetLanKey = key;
        [sender setTitle:value forState:UIControlStateNormal];
    };
    [self presentViewController:vc animated:YES completion:nil];
}

//确认
- (IBAction)submitBtnPressed:(UIButton *)sender {

    self.SelectLanKeyBlock(self.sourceLanguageKey, self.targetLanKey);
    [self.navigationController popViewControllerAnimated:YES];
}


@end
